package com.hainatong.shiphelper.login.adapter;


import android.content.Context;
import android.view.View;


import com.base.common.utils.LanguageManageUtil;
import com.base.common.view.adapter.ada.BaseRVAdapter;
import com.base.common.view.adapter.ada.GeneralRecyclerAdapter;
import com.base.common.view.adapter.bean.HeaderBean;
import com.base.common.view.adapter.connector.BaseItemMultiType;
import com.base.common.view.adapter.connector.BaseUniversalItemMultiType;
import com.hainatong.shiphelper.R;
import com.hainatong.shiphelper.databinding.ItemSelectLanguageBinding;
import com.hainatong.shiphelper.login.model.LanguageBean;
import com.hainatong.shiphelper.mainhome.MainHomeActivity;


public class LanguageAdapter extends GeneralRecyclerAdapter {


    @Override
    public void initMultiItemType() {

        putMultiItemType(new BaseUniversalItemMultiType<HeaderBean>(R.layout.driver_dp10) {
            @Override
            public int getItemViewType() {
                return TYPE_HEAD;
            }
        });

        putMultiItemType(new BaseItemMultiType<LanguageBean, ItemSelectLanguageBinding>() {
            @Override
            public int getLayoutId() {
                return R.layout.item_select_language;
            }


            @Override
            public void onItemClick(View view, BaseRVAdapter adapter, int onclickType, int position, LanguageBean bean) {
                super.onItemClick(view, adapter, onclickType, position, bean);
                setSelectPosition(position);
                selectLanguage(view.getContext(), bean.getLocalType());
            }
        });
    }


    /**
     * 设置 语言  重启主页面
     *
     * @param select 0跟随系统  1简体中文  2English      3
     */
    private void selectLanguage(Context context, int select) {
        LanguageManageUtil.saveSelectLanguage(select);
        MainHomeActivity.reStart(context);
    }

}
